/*******************************************************************************
 * Copyright (c) 2012 March and Conquest.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package mrusanov.towers.main.ui.stats;

import mrusanov.towers.localization.Localization;
import mrusanov.towers.stats.GameStatistics;
import mrusanov.towers.stats.PlayersPair;

import org.netbeans.swing.outline.RowModel;

public class GameStatisticsRowModel implements RowModel {

	private final static int SCORE_COLUMN = 0;
	private final static int WINNER_COLUMN = 1;

	@Override
	public int getColumnCount() {
		// battle = score, winner
		// pair = score
		return 2;
	}

	@Override
	public Object getValueFor(Object node, int column) {
		if (node instanceof GameStatisticsRoot) {
			return null;
		}

		if (node instanceof PlayersPair) {
			if (column == SCORE_COLUMN) {
				PlayersPair pair = (PlayersPair) node;
				return pair.getFirstWon() + ":" + pair.getSecondWon();
			} else {
				return null;
			}
		}

		if (node instanceof GameStatistics) {
			GameStatistics stats = (GameStatistics) node;
			switch (column) {
				case SCORE_COLUMN:
					return stats.getWinnersTowerHeight() + ":" + stats.getLosersTowerHeight();
				case WINNER_COLUMN:
					return stats.getWinner();
			}
		}

		throw new IllegalArgumentException("Unknown column number [" + column + "] or object class " + node);
	}

	@Override
	public Class<?> getColumnClass(int column) {
		switch (column) {
			case SCORE_COLUMN:
				return String.class;
			case WINNER_COLUMN:
				return String.class;
			default:
				throw new IllegalArgumentException("Column number [" + column + "]is illegal ");
		}
	}

	@Override
	public boolean isCellEditable(Object node, int column) {
		// statistics is not editable
		return false;
	}

	@Override
	public void setValueFor(Object node, int column, Object value) {
		// statistics is not editable
	}

	@Override
	public String getColumnName(int column) {
		switch (column) {
			case SCORE_COLUMN:
				return Localization.getString("ui.score");
			case WINNER_COLUMN:
				return Localization.getString("ui.winner");
			default:
				throw new IllegalArgumentException("Column number [" + column + "]is illegal ");
		}
	}

}
